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 7 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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
"snapshot-diff": "0.4.0",
"strip-ansi": "4.0.0",
"tempy": "0.2.1",
"webpack": "3.12.0"
"terser-webpack-plugin": "1.4.1",
"webpack": "4.39.1"
},
"scripts": {
"prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
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/", "v13");
const bundleCache = new Cache(".cache/", "v15");
await bundleCache.load();

console.log(chalk.inverse(" Building packages "));
Expand Down
27 changes: 19 additions & 8 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 @@ -176,14 +176,25 @@ function getWebpackConfig(bundle) {
path: path.resolve(root, "dist"),
filename: bundle.output,
library: ["prettierPlugins", bundle.name],
libraryTarget: "umd"
},
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
})
]
libraryTarget: "umd",
// https://github.com/webpack/webpack/issues/6642
globalObject: 'new Function("return this")()'
}
};

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