Skip to content

Commit

Permalink
fix(config): fix issue with configuration.rb, generate config
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers committed Jul 26, 2020
1 parent ba62564 commit 3d6a8f1
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaults
72 changes: 72 additions & 0 deletions examples/rails-without-webpack/config/snowpacker/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module.exports = function() {
const validEnv = ['development', 'test', 'production']
const currentEnv = process.env["NODE_ENV"]
const isDevelopmentEnv = (currentEnv === "development")
const isProductionEnv = (currentEnv === 'production')
const isTestEnv = (currentEnv === 'test')

if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}

return {
presets: [
isTestEnv && [
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
'@babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
loose: true
}
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
corejs: false
}
],
[
'@babel/plugin-transform-regenerator',
{
async: false
}
]
].filter(Boolean)
}
}
12 changes: 12 additions & 0 deletions examples/rails-without-webpack/config/snowpacker/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
plugins: [
require('postcss-import'),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
})
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const output_path = process.env["SNOWPACKER_OUTPUT_PATH"]
const port = process.env["SNOWPACKER_PORT"]
const mount_dir = process.env["SNOWPACKER_MOUNT_DIR"]
const babel_config = process.env["SNOWPACKER_BABEL_CONFIG_FILE"]
const postcss_config = process.env["SNOWPACKER_POSTCSS_CONFIG_FILE"]

// not currently supported
// const hostname = process.env["SNOWPACKER_HOSTNAME"]

const scripts = {
"mount:web_modules": `mount web_modules --to /${output_path}`,
"mount:__snowpack__": `mount __snowpack__ --to /${output_path}`,
"mount:snowpacks": `mount ${mount_dir} --to /${output_path}`,
"build:css": `postcss --config ${postcss_config}`,
"build:js,jsx,ts,tsx": `babel --config-file ${babel_config} \
--out-dir ${process.cwd()} \
${mount_dir}`
}

const installOptions = {
NODE_ENV: true
}

const devOptions = {
port: parseInt(port, 10),
open: "none",
out: "public"
}

const buildOptions = {
clean: true,
baseUrl: "/"
}

module.exports = {
scripts,
plugins: ["@snowpack/babel-plugin-package-import"],
installOptions,
devOptions,
buildOptions
}

1 change: 1 addition & 0 deletions lib/snowpacker/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Snowpacker
class Configuration
attr_accessor :config_dir
attr_accessor :config_file
attr_accessor :babel_config_file
attr_accessor :postcss_config_file
Expand Down

0 comments on commit 3d6a8f1

Please sign in to comment.