2018-10-09 20:30:59 +08:00
|
|
|
# example.js
|
|
|
|
|
2019-05-10 03:34:28 +08:00
|
|
|
```javascript
|
2018-10-09 20:30:59 +08:00
|
|
|
console.log(process.env.NODE_ENV);
|
|
|
|
|
2019-08-13 04:59:09 +08:00
|
|
|
import "./example.css";
|
2018-10-09 20:30:59 +08:00
|
|
|
import "react";
|
|
|
|
import "react-dom";
|
|
|
|
import "acorn";
|
|
|
|
import "core-js";
|
|
|
|
import "date-fns";
|
|
|
|
```
|
|
|
|
|
|
|
|
# webpack.config.js
|
|
|
|
|
2019-05-10 03:34:28 +08:00
|
|
|
```javascript
|
2018-10-09 20:30:59 +08:00
|
|
|
const path = require("path");
|
|
|
|
module.exports = (env = "development") => ({
|
|
|
|
mode: env,
|
2019-08-12 19:41:23 +08:00
|
|
|
infrastructureLogging: {
|
2019-08-13 04:59:09 +08:00
|
|
|
// Optional: print more verbose logging about caching
|
2019-08-12 19:41:23 +08:00
|
|
|
level: "verbose"
|
|
|
|
},
|
2018-10-09 20:30:59 +08:00
|
|
|
cache: {
|
|
|
|
type: "filesystem",
|
2019-08-13 04:59:09 +08:00
|
|
|
|
2019-08-12 22:37:12 +08:00
|
|
|
// changing the cacheDirectory is optional,
|
|
|
|
// by default it will be in `node_modules/.cache`
|
2019-08-13 04:59:09 +08:00
|
|
|
cacheDirectory: path.resolve(__dirname, ".cache"),
|
|
|
|
|
|
|
|
// Add additional dependencies to the build
|
|
|
|
buildDependencies: {
|
|
|
|
// recommended to invalidate cache on config changes
|
|
|
|
// This also makes all dependencies of this file build dependencies
|
|
|
|
config: [__filename]
|
|
|
|
// By default webpack and loaders are build dependencies
|
|
|
|
}
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: ["style-loader", "css-loader"]
|
|
|
|
}
|
|
|
|
]
|
2018-10-09 20:30:59 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
# Info
|
|
|
|
|
|
|
|
```
|
2019-11-15 07:06:30 +08:00
|
|
|
Hash: 0a1b2c3d4e5f6a7b8c9d
|
|
|
|
Version: webpack 5.0.0-beta.6
|
|
|
|
Asset Size
|
|
|
|
output.js 2 MiB [emitted] [name: main]
|
|
|
|
Entrypoint main = output.js
|
2019-11-19 21:10:28 +08:00
|
|
|
chunk output.js (main) 1.74 MiB (javascript) 0 bytes (runtime) [entry]
|
2019-11-15 07:06:30 +08:00
|
|
|
> ./example.js main
|
2019-11-19 21:10:28 +08:00
|
|
|
529 chunk modules
|
2018-10-09 20:30:59 +08:00
|
|
|
```
|