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

Minify postcss parser #6395

Merged
merged 9 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"snapshot-diff": "0.4.0",
"strip-ansi": "4.0.0",
"tempy": "0.2.1",
"terser-webpack-plugin": "1.4.1",
"webpack": "4.39.1"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function run(params) {
await execa("rm", ["-rf", ".cache"]);
}

const bundleCache = new Cache(".cache/", "v14");
const bundleCache = new Cache(".cache/", "v15");
await bundleCache.load();

console.log(chalk.inverse(" Building packages "));
Expand Down
22 changes: 15 additions & 7 deletions scripts/build/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function getWebpackConfig(bundle) {
}

const root = path.resolve(__dirname, "..", "..");
return {
const config = {
entry: path.resolve(root, bundle.input),
module: {
rules: [
Expand All @@ -179,14 +179,22 @@ function getWebpackConfig(bundle) {
libraryTarget: "umd",
// https://github.com/webpack/webpack/issues/6642
globalObject: 'new Function("return this")()'
},
optimization: {
// TODO: enable this
// `parser-postcss.js` can't work with terser
// https://github.com/prettier/prettier/pull/6200#issuecomment-500018106
minimize: false
}
};

if (bundle.terserOptions) {
const TerserPlugin = require("terser-webpack-plugin");

config.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: bundle.terserOptions
})
]
};
}

return config;
}

function runWebpack(config) {
Expand Down
9 changes: 8 additions & 1 deletion scripts/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const PROJECT_ROOT = path.resolve(__dirname, "../..");
* @property {string[]} externals - array of paths that should not be included in the final bundle
* @property {Object.<string, string>} replace - map of strings to replace when processing the bundle
* @property {string[]} babelPlugins - babel plugins
* @property {Object?} terserOptions - options for `terser`

* @typedef {Object} CommonJSConfig
* @property {Object} namedExports - for cases where rollup can't infer what's exported
Expand Down Expand Up @@ -59,7 +60,13 @@ const parsers = [
input: "src/language-css/parser-postcss.js",
target: "universal",
// postcss has dependency cycles that don't work with rollup
bundler: "webpack"
bundler: "webpack",
// postcss need keep_fnames when minify
terserOptions: {
mangle: {
keep_fnames: true
}
}
},
{
input: "src/language-graphql/parser-graphql.js",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6785,7 +6785,7 @@ tempy@0.2.1:
temp-dir "^1.0.0"
unique-string "^1.0.0"

terser-webpack-plugin@^1.4.1:
terser-webpack-plugin@1.4.1, terser-webpack-plugin@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.1.tgz#61b18e40eaee5be97e771cdbb10ed1280888c2b4"
integrity sha512-ZXmmfiwtCLfz8WKZyYUuuHf3dMYEjg8NrjHMb0JqHVHVOSkzp3cW2/XG1fP3tRhqEqSzMwzzRQGtAPbs4Cncxg==
Expand Down