mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-25 06:53:00 +00:00
build: Compress code in production environments
This commit is contained in:
parent
6f7e682927
commit
b9cbea5c96
1 changed files with 61 additions and 56 deletions
117
rollup.config.js
117
rollup.config.js
|
@ -9,66 +9,71 @@ import { terser } from "rollup-plugin-terser";
|
||||||
import postcss_import from 'postcss-import';
|
import postcss_import from 'postcss-import';
|
||||||
import postcss_copy from 'postcss-copy';
|
import postcss_copy from 'postcss-copy';
|
||||||
|
|
||||||
|
let plugins = [
|
||||||
|
resolve({
|
||||||
|
// use "module" field for ES6 module if possible
|
||||||
|
module: true, // Default: true
|
||||||
|
|
||||||
|
// use "jsnext:main" if possible
|
||||||
|
// – see https://github.com/rollup/rollup/wiki/jsnext:main
|
||||||
|
jsnext: true, // Default: false
|
||||||
|
|
||||||
|
// use "main" field or index.js, even if it's not an ES6 module
|
||||||
|
// (needs to be converted from CommonJS to ES6
|
||||||
|
// – see https://github.com/rollup/rollup-plugin-commonjs
|
||||||
|
main: true, // Default: true
|
||||||
|
|
||||||
|
// some package.json files have a `browser` field which
|
||||||
|
// specifies alternative files to load for people bundling
|
||||||
|
// for the browser. If that's you, use this option, otherwise
|
||||||
|
// pkg.browser will be ignored
|
||||||
|
browser: true, // Default: false
|
||||||
|
|
||||||
|
// not all files you want to resolve are .js files
|
||||||
|
extensions: ['.mjs', '.js', '.jsx', '.json'], // Default: [ '.mjs', '.js', '.json', '.node' ]
|
||||||
|
}),
|
||||||
|
|
||||||
|
commonjs({
|
||||||
|
|
||||||
|
}),
|
||||||
|
|
||||||
|
postcss({
|
||||||
|
plugins: [
|
||||||
|
postcss_import({}),
|
||||||
|
postcss_copy({
|
||||||
|
dest: "app",
|
||||||
|
template: "resources/[name].[ext]"
|
||||||
|
})
|
||||||
|
// postcss_url(),
|
||||||
|
// postcss_url({
|
||||||
|
// url: "copy",
|
||||||
|
// basePath: path.resolve("."),
|
||||||
|
// assetPath: "resources"
|
||||||
|
// })
|
||||||
|
],
|
||||||
|
// Save it to a .css file - we'll reference it ourselves thank you
|
||||||
|
// very much
|
||||||
|
extract: true,
|
||||||
|
sourceMap: true,
|
||||||
|
//minimize: true, // Causes an error at the moment for some reason
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
if(process.env.NODE_ENV == "production") {
|
||||||
|
console.log("[config] In production environment - minifying JS");
|
||||||
|
plugins.push(terser({
|
||||||
|
numWorkers: os.cpus().length,
|
||||||
|
compress: {
|
||||||
|
ecma: 6
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: 'client_src/js/index.mjs',
|
input: 'client_src/js/index.mjs',
|
||||||
output: {
|
output: {
|
||||||
file: 'app/app.js',
|
file: 'app/app.js',
|
||||||
format: 'esm'
|
format: 'esm'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins
|
||||||
resolve({
|
|
||||||
// use "module" field for ES6 module if possible
|
|
||||||
module: true, // Default: true
|
|
||||||
|
|
||||||
// use "jsnext:main" if possible
|
|
||||||
// – see https://github.com/rollup/rollup/wiki/jsnext:main
|
|
||||||
jsnext: true, // Default: false
|
|
||||||
|
|
||||||
// use "main" field or index.js, even if it's not an ES6 module
|
|
||||||
// (needs to be converted from CommonJS to ES6
|
|
||||||
// – see https://github.com/rollup/rollup-plugin-commonjs
|
|
||||||
main: true, // Default: true
|
|
||||||
|
|
||||||
// some package.json files have a `browser` field which
|
|
||||||
// specifies alternative files to load for people bundling
|
|
||||||
// for the browser. If that's you, use this option, otherwise
|
|
||||||
// pkg.browser will be ignored
|
|
||||||
browser: true, // Default: false
|
|
||||||
|
|
||||||
// not all files you want to resolve are .js files
|
|
||||||
extensions: ['.mjs', '.js', '.jsx', '.json'], // Default: [ '.mjs', '.js', '.json', '.node' ]
|
|
||||||
}),
|
|
||||||
|
|
||||||
commonjs({
|
|
||||||
|
|
||||||
}),
|
|
||||||
|
|
||||||
postcss({
|
|
||||||
plugins: [
|
|
||||||
postcss_import({}),
|
|
||||||
postcss_copy({
|
|
||||||
dest: "app",
|
|
||||||
template: "resources/[name].[ext]"
|
|
||||||
})
|
|
||||||
// postcss_url(),
|
|
||||||
// postcss_url({
|
|
||||||
// url: "copy",
|
|
||||||
// basePath: path.resolve("."),
|
|
||||||
// assetPath: "resources"
|
|
||||||
// })
|
|
||||||
],
|
|
||||||
// Save it to a .css file - we'll reference it ourselves thank you
|
|
||||||
// very much
|
|
||||||
extract: true,
|
|
||||||
sourceMap: true,
|
|
||||||
//minimize: true, // Causes an error at the moment for some reason
|
|
||||||
}),
|
|
||||||
|
|
||||||
// terser({
|
|
||||||
// numWorkers: os.cpus().length,
|
|
||||||
// compress: {
|
|
||||||
// ecma: 6
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue