1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const path = require("path");
const webpack = require("webpack");
const { ResourceUriPlugin } = require("./tools/resourceUriPlugin");
const absolute = relPath => path.join(__dirname, relPath);
const resourcePathRegEx = /^resource:\/\/activity-stream\//;
module.exports = (env = {}) => ({
mode: "none",
entry: absolute("content-src/activity-stream.jsx"),
output: {
path: absolute("data/content"),
filename: "activity-stream.bundle.js",
library: "NewtabRenderUtils",
},
// TODO: switch to eval-source-map for faster builds. Requires CSP changes
devtool: env.development ? "inline-source-map" : false,
plugins: [
// The ResourceUriPlugin handles translating resource URIs in import
// statements in .mjs files, in a similar way to what babel-jsm-to-commonjs
// does for jsm files.
new ResourceUriPlugin({ resourcePathRegEx }),
new webpack.BannerPlugin(
`THIS FILE IS AUTO-GENERATED: ${path.basename(__filename)}`
),
new webpack.optimize.ModuleConcatenationPlugin(),
],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules\/(?!@fluent\/).*/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-react"],
plugins: ["@babel/plugin-proposal-optional-chaining"],
},
},
{
test: /\.jsm$/,
exclude: /node_modules/,
loader: "babel-loader",
// Converts .jsm files into common-js modules
options: {
plugins: [
[
"./tools/babel-jsm-to-commonjs.js",
{
basePath: resourcePathRegEx,
removeOtherImports: true,
replace: true,
},
],
],
},
},
],
},
// This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.jsm"
resolve: {
extensions: [".js", ".jsx"],
modules: ["node_modules", "."],
fallback: {
stream: require.resolve("stream-browserify"),
},
},
externals: {
"prop-types": "PropTypes",
react: "React",
"react-dom": "ReactDOM",
redux: "Redux",
"react-redux": "ReactRedux",
"react-transition-group": "ReactTransitionGroup",
},
});
|