Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esm builds #583

Merged
merged 12 commits into from Jul 9, 2018
7 changes: 4 additions & 3 deletions packages/cli/lib/index.js
Expand Up @@ -23,14 +23,15 @@ prog
.command('build [src]')
.describe('Create a production build')
.option('--src', 'Specify source directory', 'src')
.option('--dest', 'Specify output directory', 'build')
.option('--dest', 'Specify output directory', 'build')
.option('--cwd', 'A directory to use instead of $PWD', '.')
.option('--sw', 'Generate and attach a Service Worker', true)
.option('--sw', 'Generate and attach a Service Worker', true)
.option('--json', 'Generate build stats for bundle analysis')
.option('--template', 'Path to custom HTML template')
.option('--analyze', 'Launch interactive Analyzer to inspect production bundle(s)')
.option('--prerenderUrls', 'Path to pre-rendered routes config', 'prerender-urls.json')
.option('-c, --config', 'Path to custom CLI config', 'preact.config.js')
.option('-c, --config', 'Path to custom CLI config', 'preact.config.js')
.option('--esm', '[HIGHLY EXPERIMENTAL] Builds ES-2015 bundles for your code.', 'esm')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces instead of tabs again 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll fix my editor... 😑.

.action(commands.build);

prog
Expand Down
18 changes: 6 additions & 12 deletions packages/cli/lib/lib/babel-config.js
Expand Up @@ -18,20 +18,14 @@ module.exports = function (env, options={}) {
}]
],
plugins: [
require.resolve('babel-plugin-syntax-dynamic-import'),
require.resolve('babel-plugin-transform-object-assign'),
require.resolve('@babel/plugin-syntax-dynamic-import'),
require.resolve('@babel/plugin-transform-object-assign'),
require.resolve('babel-plugin-transform-decorators-legacy'),
require.resolve('babel-plugin-transform-class-properties'),
require.resolve('babel-plugin-transform-export-extensions'),
require.resolve('babel-plugin-transform-object-rest-spread'),
require.resolve('babel-plugin-transform-react-constant-elements'),
require.resolve('@babel/plugin-proposal-class-properties'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),
require.resolve('@babel/plugin-transform-react-constant-elements'),
isProd && require.resolve('babel-plugin-transform-react-remove-prop-types'),
[require.resolve('babel-plugin-transform-react-jsx'), { pragma: 'h' }],
// [require.resolve('babel-plugin-jsx-pragmatic'), {
// module: 'preact',
// export: 'h',
// import: 'h'
// }]
[require.resolve('@babel/plugin-transform-react-jsx'), { pragma: 'h' }],
].filter(Boolean)
};
};
16 changes: 13 additions & 3 deletions packages/cli/lib/lib/webpack/webpack-client-config.js
Expand Up @@ -11,6 +11,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const RenderHTMLPlugin = require('./render-html-plugin');
const PushManifestPlugin = require('./push-manifest');
const baseConfig = require('./webpack-base-config');
const BabelEsmPlugin = require('babel-esm-plugin');
const { normalizePath } = require('../../util');

const cleanFilename = name => name.replace(/(^\/(routes|components\/(routes|async))\/|(\/index)?\.js$)/g, '');
Expand Down Expand Up @@ -75,7 +76,7 @@ function clientConfig(env) {

plugins: [
...RenderHTMLPlugin(env),
new PushManifestPlugin(),
new PushManifestPlugin(),
new CopyWebpackPlugin([
...(
existsSync(source('manifest.json'))
Expand Down Expand Up @@ -108,7 +109,7 @@ function isProd(config) {
plugins: [
new webpack.DefinePlugin({
'process.env.ADD_SW': config.sw
}),
})
],

optimization: {
Expand Down Expand Up @@ -175,7 +176,16 @@ function isProd(config) {
]
}),
);
}
}

if (config.esm) {
prodConfig.plugins.push(
new BabelEsmPlugin({
filename: '[name].[chunkhash:5].esm.js',
chunkFilename: '[name].chunk.[chunkhash:5].esm.js'
}),
);
}

if (config.analyze) {
prodConfig.plugins.push(
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/package.json
Expand Up @@ -47,18 +47,18 @@
},
"dependencies": {
"autoprefixer": "^8.4.1",
"babel-loader": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0-beta.47",
"@babel/plugin-transform-object-assign": "^7.0.0-beta.47",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.47",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.47",
"@babel/plugin-transform-react-constant-elements": "^7.0.0-beta.47",
"@babel/plugin-transform-react-jsx": "^7.0.0-beta.47",
"@babel/preset-env": "^7.0.0-beta.47",
"babel-esm-plugin": "0.0.9",
"babel-loader": "^8.0.0-beta.3",
"babel-plugin-jsx-pragmatic": "^1.0.2",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-constant-elements": "^6.23.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-plugin-transform-react-remove-prop-types": "^0.4.5",
"babel-preset-env": "^1.3.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this required? Preact build command fails at the moment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look up a couple of lines, has to be changed in the babel config though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah...

"babel-register": "^6.24.1",
"bluebird": "^3.5.0",
"chalk": "^2.4.1",
Expand Down